/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

using System;

using TypeOutputStream = argot.TypeOutputStream;
using TypeElement = argot.TypeElement;

using MetaSequence = argot.meta.MetaSequence;
using MetaExpression = argot.meta.MetaExpression;
using MetaReference = argot.meta.MetaReference;

namespace argot.data
{

	public class MixedDataWriter
	:TypeWriter
	{
		public virtual void Write(TypeOutputStream oStream, System.Object o, TypeElement element)
		{
			MixedData data = (MixedData) o;
			oStream.WriteObject( "s32", data.getInt() );
			oStream.WriteObject( "s16", data.getShort() );
			oStream.WriteObject( "u8ascii", data.getString() );
		}
	}

	public class MixedData 
	{
		public static String TYPENAME = "mixeddata";

		private int _anInt;
		private short _aShort;
		private String _anAscii;
	
		public MixedData( int anInt, short aShort, String anAscii )
		{
			_anInt = anInt;
			_aShort = aShort;
			_anAscii = anAscii;
		}
	
		public int getInt()
		{
			return _anInt;
		}
	
		public short getShort()
		{
			return _aShort;
		}
	
		public String getString()
		{
			return _anAscii;
		}

		/*
		* This should be contained in a dictionary file instead
		* of being created in code.  Useful here for testing.
		*/
		public static void Register( TypeLibrary library )
		{
			library.Register( MixedData.TYPENAME, 
				new MetaSequence(
					new MetaExpression[] {
						new MetaReference( library.GetId("s32"), "s32"),
						new MetaReference( library.GetId("s16"), "s16"),
						new MetaReference( library.GetId("u8ascii"), "u8ascii")
					}
				),
				new TypeReaderAuto( typeof(MixedData) ),
				new MixedDataWriter(),
				typeof(MixedData)
			);
		}
	}

}
